<?php

namespace app\admin\model;

use think\Model;

class TrainChild extends Model
{
    protected $autoWriteTimestamp = true;

    protected $pk = 'child_id';

    public static function getList($id)
    {
        $where = [];
        $limit = input('get.limit');
        $page = input('get.page');
        $where[] = ['a.train_id', '=', $id];
        $list = self::alias('a')
            ->join('video_list vl', 'a.video_id = vl.video_id')
            ->order('a.child_id', 'desc')
            ->where($where)
            ->field('a.*,vl.video_title')
            ->paginate($limit);
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit, 'page' => $page]];
    }

    public static function countTrainTimes($trainId)
    {
        return self::where(['train_id' => $trainId])
            ->count();
    }
}